<?php
namespace app\admin\model;
use think\Model;
use think\Db;

class BusChannelTempConfig extends Model
{
    public function searchOffRedisAttr($query, $value, $data)
    {
        if(isMmsOrSms()){
            $query->where('off_redis','=', 0);
        }
    }
	public function getListAll($request)
	{
        $data = $this->withSearch(['off_redis'])->alias('bsc')
        ->field('bsc.*,bus_channel.company_name')
        ->join('bus_channel','bsc.cid = bus_channel.channel_id','left');

        switch (session('user_type')) {
            case 'admin':
                # code...
                if($request['cid'])
                {
                    $data = $data->where('bsc.cid',$request['cid']);
                }
                break;
            case 'channel':
                $data = $data->where('bsc.cid',session('relate_id'));
                break;

            default:
                exit;
                break;
        }

        $data = $data->order('channel_id desc,onoff desc,id desc')
        ->paginate($request['limit'])
        ->toarray();

        foreach ($data['data'] as $key => $value) {

            $data['data'][$key]['company_name'] = $value['cid'] . '-' . $value['company_name'];

            switch ($value['onoff']) {
                case '0':
                    $data['data'][$key]['onoff'] = '关闭';
                    $data['data'][$key]['onoff_'] = '<a href="javascript:;" onClick="edit('.$value['id'].',1)" style="color:green;">开启</a>';
                    break;
                case '1':
                    $data['data'][$key]['onoff'] = '开启';
                    $data['data'][$key]['onoff_'] = '<a href="javascript:;" onClick="edit('.$value['id'].',0)" style="color:#E81033;">关闭</a>';
                    break;
            }
        }

        return $data;
	}
}